<template>
  <div class="home">
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="asideWidth" style="min-height: 100vh; background-color: #001529;">
        <div
          style="height: 60px; display: flex; align-items: center;justify-content: center; font-weight: bold; color: aliceblue;">
          <img src="@/assets/logo.jpg" alt="" width="40px" height="40px">
          <span class="logo-title" v-show="!isCollapse">智能垃圾分类系统</span>
        </div>

        <el-menu :collapse="isCollapse" :collapse-transition="false" router background-color="#001529"
          text-color="rgba(255,255,255,0.65)" active-text-color="#fff" style="border: none;"
          :default-active="$route.path">
          <el-menu-item index="/home">
            <i class="el-icon-s-home"></i>
            <span slot="title">系统首页</span>
          </el-menu-item>

          <el-menu-item index="/banner">
            <i class="el-icon-picture"></i>
            <span slot="title">轮播图管理</span>
          </el-menu-item>

          <el-menu-item index="/article">
            <i class="el-icon-s-comment"></i>
            <span slot="title">文章管理</span>
          </el-menu-item>

          <el-menu-item index="/goods">
            <i class="el-icon-s-goods"></i>
            <span slot="title">商品管理</span>
          </el-menu-item>

          <el-menu-item index="/trashcan">
            <i class="el-icon-delete-solid"></i>
            <span slot="title">垃圾桶信息管理</span>
          </el-menu-item>

          <el-menu-item index="/order">
            <i class="el-icon-s-order"></i>
            <span slot="title">商品订单管理</span>
          </el-menu-item>

          <el-menu-item index="/recyclingOrder">
            <i class="el-icon-s-order"></i>
            <span slot="title">回收工单管理</span>
          </el-menu-item>

          <el-submenu index="">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>信息管理</span>
            </template>
            <el-menu-item index="/admin">管理员信息</el-menu-item>
            <el-menu-item index="/user">用户信息</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-container>
        <!-- 头部区域 -->
        <el-header>
          <i :class="collapseIcon" style="font-size: 26px; margin-top: 10px;" @click="handleCollapse"></i>
          <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-left: 20px; margin-top: 15px;">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/test' }">回收工单管理</el-breadcrumb-item>
          </el-breadcrumb>

          <div style="flex: 1; width: 0; display: flex; align-items: center; justify-content: flex-end;">
            <el-dropdown placement="bottom">
              <div style="display: flex; align-items: center; cursor: default;">
                <img src="@/assets/logo.jpg" alt="" style="width: 40px; height: 40px;">
                <span>{{ user.name }}</span>
              </div>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>个人信息</el-dropdown-item>
                <el-dropdown-item>修改密码</el-dropdown-item>
                <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-header>

        <!-- 主体区域 -->
        <el-main>
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'
import request from "@/utils/request"

export default {
  name: 'HomeView',
  data() {
    return {
      isCollapse: false, // 默认不收缩
      asideWidth: '200px',
      collapseIcon: 'el-icon-s-fold',
      banner: [],
      fileList: [],
      user: JSON.parse(localStorage.getItem('user') || '{}')
    }
  },

  mounted() {
    // axios.get('http://localhost:10010/admin/banner/pageSearch?page=1&pageSize=10').then((res) => {
    //   console.log(res.data.data.records)
    //   this.banner = res.data.data.records
    // })
    request.get('/admin/banner/pageSearch?page=1&pageSize=10').then((res) => {
      console.log(res)
      this.banner = res.data.records
    })
  },

  methods: {
    handleFileUpload(res, file, fileList) {
      this.fileList = fileList
    },
    handleCollapse() {
      this.isCollapse = !this.isCollapse
      if (this.isCollapse) {
        this.asideWidth = '64px'
        this.collapseIcon = 'el-icon-s-unfold'
      } else {
        this.asideWidth = '200px'
        this.collapseIcon = 'el-icon-s-fold'
      }
    },
    logout() {
      localStorage.removeItem('user')
      this.$router.push('/login')
    }
  },
  components: {
    HelloWorld
  }
}
</script>
<style>
.el-menu--inline {
  background-color: #000c17 !important;
}

.el-menu--inline .el-menu-item {
  background-color: #000c17 !important;
  /* margin-left: 10px !important; */
}

.el-submenu {
  text-align: left !important;
  height: 40px !important;
  line-height: 40px !important;
  /* margin: 5px !important; */
}

.el-menu-item:hover,
.el-submenu__title:hover {
  color: #fff !important;
}

.el-submenu__title:hover i {
  color: #fff !important;
}

.el-menu-item.is-active {
  background-color: #1890ff !important;
  border-radius: 10px !important;
  /* margin: 5px !important; */
  width: 96%;
  margin-left: 2%;
}

.el-menu-item.is-active i,
.el-menu-item.is-active .el-tooltip {
  margin-left: -2%;
}

.el-menu-item {
  text-align: left !important;
  height: 40px !important;
  line-height: 40px !important;
  /* margin: 5px !important; */
}

.el-menu__title {
  height: 40px !important;
  line-height: 40px !important;
  /* margin: 5px !important; */
}

.el-menu-item,
.el-submenu__title {
  height: 40px !important;
  line-height: 40px !important;
}

.el-submenu .el-menu-item {
  min-width: 0 !important;
  margin-right: 10% !important;
  padding-left: 54px !important;
  /* margin-left: 20px; */
}

.el-menu--inline .el-menu-item.is-active {
  width: 96% !important;
  padding-left: 50px !important;
}

.el-aside {
  transition: width .3s;
  box-shadow: 2px 0 6px rgba(0, 21, 41, .35);
}

.logo-title {
  margin-left: 5px;
  transition: all .3s;
}

.el-header {
  margin-left: 7px !important;
  border-radius: 10px !important;
  box-shadow: 2px 0 6px rgba(0, 21, 41, .35);
  display: flex;
  text-align: center;
}
</style>
